    const domain = 'http://j221w49004.iok.la/'

    async function request({
        method = 'post',
        url,
        data,
    }) {
        //   Vue.prototype.$Progress.start()
        try {
            let res = await axios({
                method,
                url,
                data,
                params: method.toLowerCase() == 'get' ? data : undefined,
                baseURL: domain,
                withCredentials: true, // 是否允许跨域设置cookie
                headers: {
                    hotelid: localStorage.getItem('hotelId')
                }
            })
            if (!res.data.success) throw new Error(res.data.message)
            return res.data.result
        } catch (err) {
            alert(err)
            throw err
        } finally {
            // Vue.prototype.$Progress.finish()
        }
    }

    let api = {
        getJsApiSign(data) {
            return request({
                method: 'get',
                url: '/api/wechat/card/getJsApiSign',
                data,
            })
        },

        // 通过code获取openid
        getOpenidByCode(data) {
            return request({
                method: 'get',
                url: '/api/wechat/card/getOpenid',
                data
            })
        },

        // 获取积分使用明细
        getIntegralList(openid) {
            return request({
                method: 'get',
                url: `/api/wechat/card/getIntegralList/${openid}`
            })
        },

        // 获取余额消费明细
        getBalanceRecordList(openid) {
            return request({
                method: 'get',
                url: `/api/wechat/card/getBalanceRecordList/${openid}`,
            })
        },

        // 获取添加卡券时CardExt字段的签名
        getSignature(openid){
            return request({
                method: 'get',
                url: `/api/wechat/card/getSignature/${openid}`
            })
        }
    }

    function randomString(length, chars) {
        let result = '';
        for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
        return result;
    }

    async function importJsApiList(jsApiList) {
        let appId = 'wx56c01c125d7280ef';
        let nonceStr = randomString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
        let timestamp = Date.now()

        let signature = await api.getJsApiSign({
            nonceStr,
            url: window.location.href.split('#')[0],
            timestamp
        })

        wx.config({
            debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId, // 必填，公众号的唯一标识
            timestamp, // 必填，生成签名的时间戳
            nonceStr, // 必填，生成签名的随机串
            signature, // 必填，签名
            jsApiList // 必填，需要使用的JS接口列表
        });

        return await new Promise((resolve, reject) => {
            wx.ready(res => {
                resolve()
            })
            wx.error(err => {
                reject(new Error(err))
            })
        })
    }

    function getOpenid() {
        let openid = localStorage.getItem('openid')
        if (!openid) {
            window.location.replace(
                'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx56c01c125d7280ef&redirect_uri=http://j221w49004.iok.la%2Fwxmp%2Flogin.html&response_type=code&scope=snsapi_base&state=test&connect_redirect=1#wechat_redirect'
            )
            throw new Error('未登录')
        } else {
            return openid
        }
    }